package com.ice.work.moment.scheduler.job;

import com.honeybee.cloud.framework.common.constant.CommonSystemConstant;
import com.honeybee.cloud.framework.common.response.ResponseEntity;
import com.ice.work.moment.scheduler.service.ICrawlerTaskService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHandler;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Description 评论详情爬取任务
 * @Author cheng
 * @Create 2018-12-11
 * @Since 1.0.0
 */
@JobHandler(value = "commentJobHandler")
@Component
@SuppressWarnings("all")
public class CommentJobHandler extends IJobHandler {

    @Autowired
    private ICrawlerTaskService crawlerTaskService;

    @Override
    public ReturnT<String> execute(String params) {
        Integer pageSize = 200;
        Long shareId = null;
        if (StringUtils.isNotBlank(params)) {
            String[] paramArray = params.split(CommonSystemConstant.SEMICOLON);
            if (paramArray.length >= 1) {
                if (NumberUtils.isDigits(paramArray[0])) {
                    pageSize = Integer.parseInt(paramArray[0]);
                }
            }
            if (paramArray.length > 1) {
                if (NumberUtils.isDigits(paramArray[1])) {
                    shareId = Long.parseLong(paramArray[1]);
                }
            }
        }
        ResponseEntity<Void> responseEntity = crawlerTaskService.getAllShareComment(pageSize, shareId);
        return responseEntity.getSuccess() ? IJobHandler.SUCCESS : IJobHandler.FAIL;
    }

}
